home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Sound Editor / Source / SoundEditorUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  9.0 KB  |  357 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SoundEditorUtils.h
  3.  
  4.     Contains:    SoundEditor utility functions & classes
  5.  
  6.     Written by:    Steve Smith and Troy Gaul
  7.  
  8.     Copyright:    © 1994,95 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11.  
  12. #ifndef _SOUNDEDITORUTILS_
  13. #define _SOUNDEDITORUTILS_
  14.  
  15. // -- Compiler/Preprocessor Switches --
  16.  
  17. #ifndef _COMPILERDEFS_
  18. #include "CompDefs.h"
  19. #endif
  20.  
  21. // -- OpenDoc Utilities --
  22.  
  23. #ifndef _EXCEPT_
  24. // Exceptions define several important macros (ie. CHECKENV)
  25. // which are used in the SOM method dispatch glue. If Except.h
  26. // is not included early enough, exceptions may not be thrown
  27. // correctly when returning from a SOM method with "ev" parameter set.
  28. #include <Except.h>
  29. #endif
  30.  
  31. // -- OpenDoc Includes --
  32.  
  33. #ifndef SOM_ODFrame_xh
  34. #include <Frame.xh>            // So ODAcquireObject can be called on an ODFrame
  35. #endif
  36.  
  37. // -- OpenDoc Utilities --
  38.  
  39. #ifndef _ITEXT_
  40. #include <IText.h>            // ODScriptCode, ODLangCode
  41. #endif
  42.  
  43. #ifndef _ODDEBUG_
  44. #include <ODDebug.h>        // ASSERT macro for inlines
  45. #endif
  46.  
  47. #ifndef _ODUTILS_
  48. #include <ODUtils.h>        // ODAcquireObject, etc. utilities for inlines
  49. #endif
  50.  
  51. // -- Macintosh Includes --
  52.  
  53. #ifndef __DIALOGS__
  54. #include <Dialogs.h>        // For DialogPtr
  55. #endif
  56.  
  57. //------------------------------------------------------------------------------
  58. // Forward declarations
  59. //------------------------------------------------------------------------------
  60.  
  61. struct Environment;
  62. class ODDraft;
  63. class ODFrame;
  64. class ODFacet;
  65. class ODStorageUnit;
  66. class ODStorageUnitView;
  67. class ODWindow;
  68.  
  69. //------------------------------------------------------------------------------
  70. // Typedefs
  71. //------------------------------------------------------------------------------
  72.  
  73. // Define the FINF type.  FINF is a font information resource that is used
  74. // to specify a font, style, and size as an entry in an array of the same
  75. // that is to exist in a 'FINF' resource in the editor.
  76. struct FINF {
  77.     short    font;
  78.     short    face;
  79.     short    size;
  80. };
  81.  
  82. typedef struct FINF *FINFPtr;
  83.  
  84. //------------------------------------------------------------------------------
  85. // Function Prototypes
  86. //------------------------------------------------------------------------------
  87.  
  88. ODIText*        GetPartName(Environment* ev, ODPart* part, ODType category);
  89. ODBoolean        NamesAreEquivalent(Environment* ev, ODIText* fileName,
  90.                                         ODIText* partName);
  91. void            GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
  92.                                         ODLangCode* language);
  93. void            FixedToIntRect(ODRect& fixedRect, Rect& intRect);
  94. void            IntToFixedRect(Rect& intRect, ODRect& fixedRect);
  95. void            LoadThumbnail(Environment* ev, Handle* thumbnail);
  96. Rect            TilePartWindow(Environment* ev, Rect* facetBounds,
  97.                                         Rect* partWindowBounds);
  98. ODUShort        CountFacets(Environment* ev, ODFrame* frame);
  99. FINF            GetIndFINF(short id, short num);
  100. void            SetDialogDefaults(DialogPtr dialog, ODUShort finfID = 0,
  101.                                           ODUShort index = 0);
  102.  
  103. void            DrawTime(Environment* ev, ODFacet* facet,
  104.                                         Rect& bounds, ODSShort size, 
  105.                                         ODSShort time);
  106.  
  107. ODHandle        Read1IndResource(ResType type, short index);
  108. void            DrawEditorPicture(short index, Rect& bounds);
  109.  
  110. //------------------------------------------------------------------------------
  111. // TempFocus
  112. //------------------------------------------------------------------------------
  113.  
  114. class TempFocus : Destructo {
  115.  
  116. public:
  117.     TempFocus(Environment*, ODTypeToken focusType, ODFrame*);
  118.     ~TempFocus();
  119.     
  120.     ODBoolean Request();
  121.     
  122. private: // disallow these:
  123.     TempFocus(const TempFocus&);
  124.     void operator=(const TempFocus&);
  125.     
  126. private:
  127.     Environment* fEv;
  128.     ODTypeToken     fFocusType;
  129.     ODFrame*     fFrameToFocus;
  130.     ODBoolean     fAcquired;
  131. };
  132.  
  133. //------------------------------------------------------------------------------
  134. // TempClipboardFocus
  135. //------------------------------------------------------------------------------
  136.  
  137. class TempClipboardFocus : public TempFocus {
  138.  
  139. public:
  140.     TempClipboardFocus(Environment*, ODFrame*);
  141. };
  142.  
  143. //------------------------------------------------------------------------------
  144. // TempHandleLockAndRememberState
  145. //------------------------------------------------------------------------------
  146.  
  147. class TempHandleLockAndRememberState : Destructo {
  148.  
  149. protected:
  150.     ODHandle fHandle; 
  151.     ODSByte fSavedState;
  152.     
  153. public:
  154.     ~TempHandleLockAndRememberState();            // restores the handle's state
  155.     TempHandleLockAndRememberState( ODHandle );   // locks the handle
  156.     operator ODHandle ()
  157.         { return fHandle; }
  158.  
  159. private: // disallow these:
  160.     TempHandleLockAndRememberState( );
  161.     TempHandleLockAndRememberState(const TempHandleLockAndRememberState& );
  162.     void operator=(const TempHandleLockAndRememberState& );
  163. };
  164.  
  165. //------------------------------------------------------------------------------
  166. // CFrameProxy (aka CFuton)
  167. //------------------------------------------------------------------------------
  168.  
  169. class CFrameProxy {
  170.  
  171. public:
  172.     CFrameProxy();
  173.     ~CFrameProxy();
  174.     
  175.     void        InitFrameProxy(ODID frameID, ODDraft* draft);
  176.     void        InitFrameProxy(Environment* ev, ODFrame* frame);
  177.     void        Purge(Environment* ev);
  178.  
  179.     ODFrame*    GetFrame(Environment* ev);
  180.     void        SetFrame(Environment* ev, ODFrame* frame);
  181.     ODBoolean    FrameIsLoaded(Environment* ev);
  182.     ODID        GetID();
  183.     ODDraft*    GetDraft();
  184.     
  185. private:
  186.     ODFrame*    fFrame;
  187.     ODID        fID;
  188.     ODDraft*    fDraft;
  189. };
  190.  
  191. //------------------------------------------------------------------------------
  192. // CFrameInfo
  193. //------------------------------------------------------------------------------
  194.  
  195. class CFrameInfo {
  196.  
  197. public:
  198.             CFrameInfo(ODSession* session);
  199.             ~CFrameInfo();
  200.     
  201.     void    Externalize(Environment* ev, ODStorageUnitView* storageUnitView);
  202.     void    CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit);
  203.     void    ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
  204.                                     ODDraftKey key, ODFrame* scopeFrame);
  205.     void    CloneInto(Environment *ev, ODDraftKey key,
  206.                                     ODStorageUnitView* storageUnitView,
  207.                                     ODFrame* scopeFrame);
  208.     void    InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView);
  209.                 
  210.     ODBoolean        IsFrameActive();
  211.     void            SetFrameActive(ODBoolean active);
  212.     ODBoolean        FrameNeedsReactivating();
  213.     void            SetFrameReactivate(ODBoolean reactivate);
  214.     ODFacet*        GetActiveFacet();
  215.     void            SetActiveFacet(ODFacet* facet);
  216.     void            SetSourceFrame(Environment* ev, ODFrame* frame);
  217.     ODFrame*        GetSourceFrame(Environment* ev);
  218.     void            ReleaseSourceFrame(Environment* ev);
  219.     ODBoolean        HasSourceFrame();
  220.     ODWindow*        AcquirePartWindow(Environment* ev);
  221.     void            SetPartWindow(Environment* ev, ODWindow* window);
  222.     void            SetDependentFrame(Environment* ev, ODFrame* frame);
  223.     ODFrame*        GetDependentFrame(Environment* ev);
  224.     ODBoolean        HasDependentFrame();
  225.     void            ReleaseDependentFrame(Environment* ev);
  226.     void            SetShouldDisposeWindow(ODBoolean should);
  227.     ODBoolean        ShouldDisposeWindow();
  228.     
  229. private:
  230.     CFrameInfo(); /* don't want parts to call */
  231.     
  232.     ODSession*        fSession;
  233.     ODBoolean        fFrameActive;
  234.     ODBoolean        fFrameReactivate;
  235.     ODBoolean        fShouldDisposeWindow;
  236.     ODFacet*        fActiveFacet;
  237.     CFrameProxy*    fSourceFrame;
  238.     CFrameProxy*    fDependentFrame;
  239.     ODID            fPartWindowID;
  240. };
  241.  
  242.  
  243. //-------------------------------------------------------------------------
  244. // Inline methods
  245. //-------------------------------------------------------------------------
  246.  
  247. //=========================================================================
  248. // CFrameProxy
  249. //=========================================================================
  250.  
  251. inline CFrameProxy::CFrameProxy()
  252. {
  253.     fFrame = kODNULL;
  254.     fID = kODNULLID;
  255.     fDraft = kODNULL;
  256. }
  257.     
  258. inline CFrameProxy::~CFrameProxy()
  259. {
  260.     ODSafeReleaseObject(fFrame);
  261. }
  262.     
  263. inline void CFrameProxy::InitFrameProxy(ODID frameID, ODDraft* draft)
  264. {
  265.     ASSERT(draft!=kODNULL, kODErrIllegalNullInput);
  266.     
  267.     fFrame = kODNULL;
  268.     fID = frameID;
  269.     fDraft = draft;
  270. }
  271.     
  272. inline void CFrameProxy::InitFrameProxy(Environment* ev, ODFrame* frame)
  273. {
  274.     ASSERT(frame!=kODNULL, kODErrIllegalNullFrameInput);
  275.     
  276.     this->SetFrame(ev,frame);
  277. }
  278.  
  279. inline ODID CFrameProxy::GetID()
  280. {
  281.     return fID;
  282. }
  283.  
  284. inline ODDraft* CFrameProxy::GetDraft()
  285. {
  286.     return fDraft;
  287. }
  288.  
  289.  
  290. //=========================================================================
  291. // CFrameInfo
  292. //=========================================================================
  293.  
  294. inline ODBoolean CFrameInfo::IsFrameActive()
  295. {
  296.     return fFrameActive;
  297. }
  298.  
  299. inline void CFrameInfo::SetFrameActive(ODBoolean active)
  300. {
  301.     fFrameActive = active;
  302. }
  303.  
  304. inline ODBoolean CFrameInfo::FrameNeedsReactivating()
  305. {
  306.     return fFrameReactivate;
  307. }
  308.  
  309. inline void CFrameInfo::SetFrameReactivate(ODBoolean reactivate)
  310. {
  311.     fFrameReactivate = reactivate;
  312. }
  313.  
  314. inline ODFacet* CFrameInfo::GetActiveFacet()
  315. {
  316.     return fActiveFacet;
  317. }
  318.  
  319. inline void CFrameInfo::SetActiveFacet(ODFacet* facet)
  320. {
  321.     fActiveFacet = facet;
  322. }
  323.  
  324. inline ODFrame* CFrameInfo::GetSourceFrame(Environment* ev)
  325. {
  326.     return fSourceFrame->GetFrame(ev);
  327. }
  328.  
  329. inline ODBoolean CFrameInfo::HasSourceFrame()
  330. {
  331.     return (fSourceFrame != kODNULL);
  332. }
  333.  
  334. inline ODFrame* CFrameInfo::GetDependentFrame(Environment* ev)
  335. {
  336.     return fDependentFrame->GetFrame(ev);
  337. }
  338.  
  339. inline ODBoolean CFrameInfo::HasDependentFrame()
  340. {
  341.     return (fDependentFrame != kODNULL);
  342. }
  343.  
  344. inline void CFrameInfo::SetShouldDisposeWindow(ODBoolean should)
  345. {
  346.     fShouldDisposeWindow = should;
  347. }
  348.  
  349. inline ODBoolean CFrameInfo::ShouldDisposeWindow()
  350. {
  351.     return fShouldDisposeWindow;
  352. }
  353.  
  354. #endif
  355.  
  356.  
  357.